export const clientLess800 = () => {
  return document.documentElement.clientWidth < 800;
};

export const checkIsMobile = () => {
  const ua = navigator.userAgent.toLowerCase();
  return (
    ua.indexOf("iphone") !== -1 ||
    ua.indexOf("android") !== -1 ||
    ua.indexOf("ipod") !== -1
  );
};

export function adjustHomeH5FontSize(designWidth = 375) {
  const currentWidth = window.innerWidth;

  const fontSize = (currentWidth / designWidth).toFixed(6);

  document.documentElement.style.fontSize = fontSize + "px";

  document.body.style.fontSize = "14rem";
}

export function adjustHomePCFontSize(
  designWidth = 1440,
  maxWidth = 1900,
  minWidth = 800
) {
  if (!["/", "/download"].includes(window.location.pathname)) {
    document.documentElement.style.fontSize = "16px";
    document.body.style.fontSize = "14px";

    return;
  }

  if (
    window.location.pathname === "/" &&
    (checkIsMobile() || clientLess800())
  ) {
    adjustHomeH5FontSize();

    return;
  }

  let currentWidth = window.innerWidth;

  if (currentWidth > maxWidth) {
    currentWidth = maxWidth;
  } else if (currentWidth < minWidth) {
    currentWidth = minWidth;
  }

  const fontSize = (currentWidth / designWidth).toFixed(6);

  document.documentElement.style.fontSize = fontSize + "px";

  document.body.style.fontSize = "16rem";
}
